//
//  Ugc_ReleaseFailure_TBV_WX.m
//  ZITHER
//
//  Created by weixin on 2018/9/29.
//  Copyright © 2018年 weixn. All rights reserved.
//

#import "Ugc_ReleaseFailure_TBV_WX.h"
#import "Ugc_ReleaseFailure_OnePicCell_WX.h"
#import "Ugc_ReleaseFailure_FourPicCell_WX.h"
#import "Ugc_ReleaseFailure_MorePicCell_WX.h"

#import "Ugc_Detail_VC_WX.h"
#import "UgcMainModel.h"

@implementation Ugc_ReleaseFailure_TBV_WX

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self defaultConfiguration];
    }
    return self;
}

-(void)setLoad{
    
}

-(void)defaultConfiguration{
    self.tableHeaderView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 20)];
    self.delegate = self;
    self.dataSource = self;
    self.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.rowHeight = UITableViewAutomaticDimension;
    self.estimatedRowHeight = 1000;
    [self registerNib:[UINib nibWithNibName:@"Ugc_ReleaseFailure_OnePicCell_WX" bundle:nil] forCellReuseIdentifier:@"Ugc_ReleaseFailure_OnePicCell_WX"];
    [self registerNib:[UINib nibWithNibName:@"Ugc_ReleaseFailure_FourPicCell_WX" bundle:nil] forCellReuseIdentifier:@"Ugc_ReleaseFailure_FourPicCell_WX"];
    [self registerNib:[UINib nibWithNibName:@"Ugc_ReleaseFailure_MorePicCell_WX" bundle:nil] forCellReuseIdentifier:@"Ugc_ReleaseFailure_MorePicCell_WX"];
}


#pragma MARK - 数据源
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return kUSER_INFO_MANAGER.arrMUgcReleaseFailure.count;
}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    UgcReleaseFailureModel *modelson = kUSER_INFO_MANAGER.arrMUgcReleaseFailure[kUSER_INFO_MANAGER.arrMUgcReleaseFailure.count-1 - indexPath.row];

    if (modelson.arrMPic.count == 1) {
        static NSString *OnePicCell = @"Ugc_ReleaseFailure_OnePicCell_WX";
        Ugc_ReleaseFailure_OnePicCell_WX *cell = [tableView dequeueReusableCellWithIdentifier:OnePicCell];
        if (cell == nil) {
            cell = [[Ugc_ReleaseFailure_OnePicCell_WX alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:OnePicCell];
        }
        cell.selectionStyle = UITableViewCellSeparatorStyleNone;
        cell.model = modelson;
        cell.indexPath = indexPath;
        @weakify(self);
        [cell setBlock:^{
            @strongify(self);
            [self reloadData];
        }];
        return cell;
    }else if(modelson.arrMPic.count == 4){
        static NSString *fourPicCell = @"Ugc_ReleaseFailure_FourPicCell_WX";
        Ugc_ReleaseFailure_FourPicCell_WX *cell = [tableView dequeueReusableCellWithIdentifier:fourPicCell];
        if (cell == nil) {
            cell = [[Ugc_ReleaseFailure_FourPicCell_WX alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:fourPicCell];
        }

        cell.selectionStyle = UITableViewCellSeparatorStyleNone;
        cell.model = modelson;
        cell.indexPath = indexPath;
        @weakify(self);
        [cell setBlock:^{
            @strongify(self);
            [self reloadData];
        }];
        return cell;
    }else{
        static NSString *sectionCell = @"Ugc_ReleaseFailure_MorePicCell_WX";
        //        NSLog(@" ========== %@",sectionCell);
        Ugc_ReleaseFailure_MorePicCell_WX *cell = [tableView dequeueReusableCellWithIdentifier:sectionCell];
        if (cell == nil) {
            cell = [[Ugc_ReleaseFailure_MorePicCell_WX alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:sectionCell];
        }

        @weakify(cell);
        @weakify(self);
        [cell setShowBigPic:^(NSIndexPath * _Nonnull indexPath, NSUInteger index) {
            @strongify(cell);
            @strongify(self);
            
            self.arrImageView = cell.arrImageView;
//            [self showBigImage:index];
        }];
        cell.selectionStyle = UITableViewCellSeparatorStyleNone;
        cell.model = modelson;
        cell.indexPath = indexPath;
        [cell setBlock:^{
            @strongify(self);
            [self reloadData];
        }];
        return cell;
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSLog(@"section == %ld,row == %ld",indexPath.section,indexPath.row);
//    UgcMainListModel *model = self.arrM[indexPath.row];
//    Ugc_Detail_VC_WX *vc = [[Ugc_Detail_VC_WX alloc]init];
//    vc.ugcId = model.ugcId;
//    [self.getNav pushViewController:vc animated:YES];
}

//-(void)showBigImage:(NSInteger)selectIndex{
//    UIImageView *imageV = self.arrImageView[selectIndex];
//    // self.model.fileList[selectIndex-100];
//
//    if (!self.imagePreviewViewController) {
//        self.imagePreviewViewController = [[QMUIImagePreviewViewController alloc] init];
//        self.imagePreviewViewController.imagePreviewView.delegate = self;
//
//        // QMUIImagePreviewViewController 对于以 window 的方式展示的情况，默认会开启手势拖拽退出预览功能。
//        // 如果使用了手势拖拽，并且退出预览时需要飞到某个 rect，则需要实现这个 block，在里面自己去 exit，如果不实现这个 block，退出动画会使用 fadeOut 那种
//
//    }
//    @weakify(self);
//    self.imagePreviewViewController.customGestureExitBlock = ^(QMUIImagePreviewViewController *aImagePreviewViewController, QMUIZoomImageView *currentZoomImageView) {
//        @strongify(self);
//        NSInteger index = aImagePreviewViewController.imagePreviewView.currentImageIndex;
//        UIImageView *imageV1 = self.arrImageView[index];
//
//        //        imageV.image = currentZoomImageView.image;
//        //            [weakSelf.imageButton setImage:currentZoomImageView.image forState:UIControlStateNormal];
//
//        [aImagePreviewViewController exitPreviewToRectInScreenCoordinate:[imageV1 convertRect:imageV1.frame toView:nil]];
//
//    };
//    self.imagePreviewViewController.imagePreviewView.currentImageIndex =  selectIndex;// 默认查看的图片的 index
//
//    [self.imagePreviewViewController startPreviewFromRectInScreenCoordinate:[imageV convertRect:imageV.frame toView:nil] cornerRadius:imageV.layer.cornerRadius];
//}
//
//
//#pragma mark - <QMUIImagePreviewViewDelegate>
//
//- (NSUInteger)numberOfImagesInImagePreviewView:(QMUIImagePreviewView *)imagePreviewView {
//    return self.arrImageView.count;
//}
//
//- (void)imagePreviewView:(QMUIImagePreviewView *)imagePreviewView renderZoomImageView:(QMUIZoomImageView *)zoomImageView atIndex:(NSUInteger)index {
//    // 模拟异步加载的情况
//    zoomImageView.reusedIdentifier = @(index);
//    [zoomImageView showLoading];
//    if ([zoomImageView.reusedIdentifier isEqual:@(index)]) {
//        [zoomImageView hideEmptyView];
//        UIImageView *imageV = self.arrImageView[index];
//        zoomImageView.image = imageV.image;
//
//    }
//    //    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//    //
//    //    });
//}
//
//- (QMUIImagePreviewMediaType)imagePreviewView:(QMUIImagePreviewView *)imagePreviewView assetTypeAtIndex:(NSUInteger)index {
//    return QMUIImagePreviewMediaTypeImage;
//}
//
//#pragma mark - <QMUIZoomImageViewDelegate>
//
//- (void)singleTouchInZoomingImageView:(QMUIZoomImageView *)zoomImageView location:(CGPoint)location {
//    //点击缩回
//    self.imagePreviewViewController.customGestureExitBlock(self.imagePreviewViewController, zoomImageView);
//}
//
//-(NSMutableArray *)arrImageView{
//    if (!_arrImageView) {
//        _arrImageView = [[NSMutableArray alloc]init];
//    }
//    return _arrImageView;
//}

-(void)removeCell:(UITableViewCell*)cell{
    NSIndexPath *cellIndexPath = [self indexPathForCell:cell];
    //先移除数组_showInfoList中的cell数据
    
    [self.arrM removeObjectAtIndex:cellIndexPath.section];
    
    [self beginUpdates];
    
//    [self deleteSections:[NSIndexSet indexSetWithIndex:cellIndexPath.section]withRowAnimation:UITableViewRowAnimationLeft];
    

    [self deleteRowsAtIndexPaths:[NSArray arrayWithObject:cellIndexPath] withRowAnimation:UITableViewRowAnimationLeft];
    [self endUpdates];
    
    // 刷新第0个section
    
    [self reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationLeft];

}

@end
